// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import zombie.characters.IsoZombie;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.math.PZMath;
import zombie.core.raknet.UdpConnection;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMovingObject;
import zombie.iso.IsoWorld;
import zombie.iso.objects.IsoDeadBody;
import zombie.network.GameServer;
import zombie.popman.NetworkZombiePacker;
import zombie.util.StringUtils;
import zombie.util.Type;

@CommandName(
    name = "removezombies"
)
@CommandArgs(
    varArgs = true
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_RemoveZombies"
)
@RequiredRight(
    requiredRights = 56
)
public class RemoveZombiesCommand extends CommandBase {
    public RemoveZombiesCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        int int0 = -1;
        int int1 = -1;
        int int2 = -1;
        int int3 = -1;
        boolean boolean0 = false;
        boolean boolean1 = false;
        boolean boolean2 = false;

        for (byte _byte = 0; _byte < this.getCommandArgsCount() - 1; _byte += 2) {
            String string0 = this.getCommandArg(Integer.valueOf(_byte));
            String string1 = this.getCommandArg(Integer.valueOf(_byte + 1));
            switch (string0) {
                case "-radius":
                    int0 = PZMath.tryParseInt(string1, -1);
                    break;
                case "-reanimated":
                    boolean0 = StringUtils.tryParseBoolean(string1);
                    break;
                case "-x":
                    int1 = PZMath.tryParseInt(string1, -1);
                    break;
                case "-y":
                    int2 = PZMath.tryParseInt(string1, -1);
                    break;
                case "-z":
                    int3 = PZMath.tryParseInt(string1, -1);
                    break;
                case "-remove":
                    boolean1 = StringUtils.tryParseBoolean(string1);
                    break;
                case "-clear":
                    boolean2 = StringUtils.tryParseBoolean(string1);
                    break;
                default:
                    return this.getHelp();
            }
        }

        if (boolean1) {
            GameServer.removeZombiesConnection = this.connection;
            return "Zombies removed.";
        } else if (int3 >= 0 && int3 < 8) {
            for (int int4 = int2 - int0; int4 <= int2 + int0; int4++) {
                for (int int5 = int1 - int0; int5 <= int1 + int0; int5++) {
                    IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int5, int4, int3);
                    if (isoGridSquare != null) {
                        if (boolean2) {
                            if (!isoGridSquare.getStaticMovingObjects().isEmpty()) {
                                for (int int6 = isoGridSquare.getStaticMovingObjects().size() - 1; int6 >= 0; int6--) {
                                    IsoDeadBody isoDeadBody = Type.tryCastTo(
                                        (IsoMovingObject)isoGridSquare.getStaticMovingObjects().get(int6), IsoDeadBody.class
                                    );
                                    if (isoDeadBody != null) {
                                        GameServer.sendRemoveCorpseFromMap(isoDeadBody);
                                        isoDeadBody.removeFromWorld();
                                        isoDeadBody.removeFromSquare();
                                    }
                                }
                            }
                        } else if (!isoGridSquare.getMovingObjects().isEmpty()) {
                            for (int int7 = isoGridSquare.getMovingObjects().size() - 1; int7 >= 0; int7--) {
                                IsoZombie isoZombie = Type.tryCastTo((IsoMovingObject)isoGridSquare.getMovingObjects().get(int7), IsoZombie.class);
                                if (isoZombie != null && (boolean0 || !isoZombie.isReanimatedPlayer())) {
                                    NetworkZombiePacker.getInstance().deleteZombie(isoZombie);
                                    isoZombie.removeFromWorld();
                                    isoZombie.removeFromSquare();
                                }
                            }
                        }
                    }
                }
            }

            LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " removed zombies near " + int1 + "," + int2, "IMPORTANT");
            return "Zombies removed.";
        } else {
            return "invalid z";
        }
    }
}
